<?php
/**
 * Created by PhpStorm.
 * User: GXF
 * Date: 15-10-14
 * Time: 上午9:56
 */
date_default_timezone_set('PRC');
function createDB(){
    $db = new SQLite3('MedicalWifi.db');//连接数据库
    $sql = "SELECT* FROM sqlite_master where type='table' and (name ='doctor' or
                name='patientResume' or name='transferRecord')";
    $result = $db->query($sql);
    for($i=0;$row=$result->fetchArray();$i++);
    if($db && $i!=3){
        /**************************************************
         *************************创建医生表****************
         * ************************************************/
        $sql = "CREATE TABLE if not exists 'doctor' (
                        'id' TEXT(20) PRIMARY KEY,
                        'name' TEXT NOT NULL,
                        'password' TEXT NOT NULL,
                        'location' TEXT NOT NULL,
                        'hospital'	TEXT NOT NULL,
                        'specialt' TEXT  NOT NULL ,
                        'abstract' TEXT NOT NULL,
                        'createTime' TEXT NOT NULL
                    );";
        $result = $db->exec($sql);
        /**************************************************
         **************************创建病历表***************
         * ************************************************/
        $sql = "CREATE TABLE if not exists 'patientResume' (
                        'id' TEXT(20) PRIMARY KEY NOT NULL,
                        'patientName' TEXT NOT NULL,
                        'patientSex' INTEGER NOT NULL,
                        'patientBirthday' TEXT NOT NULL,
                        'telephone' TEXT  NOT NULL,
                        'medicareCard' TEXT NOT  NULL,
                        'registrationNumber' TEXT NOT  NULL,
                        'conditionDescription' TEXT NOT NULL,
                        'waitingDoctorMark' INTEGER NOT NULL,
                        'finish' INTEGER  NOT NULL,
                        'createTime' TEXT NOT NULL
                    );";
        $result = $db->exec($sql);
        /**************************************************
         ****************************转诊表******************
         * ************************************************/
        $sql = "CREATE TABLE if not exists 'transferRecord' (
                        'transferID' TEXT(10) PRIMARY KEY NOT NULL,
                        'resumeID' TEXT(20) NOT NULL,
                        'doctorID' TEXT(20) NOT NULL,
                        'doctorFinishMark' INTEGER NOT NULL,
                        'transferSure' INTEGER NOT NULL,
                        'transferAgainMark' INTEGER NOT NULL,
                        'transferDoctorID' TEXT(20) NOT NULL,
                        'transferDiagnosis' TEXT NOT NULL,
                        'transferDoctorFinishMark' INTEGER NOT NULL,
                        'createTime' TEXT NOT NULL
                    );";
        $result = $db->exec($sql);
        $date = date("Y-m-d H:i:s");
        $sql = "insert into doctor values ('a','孙悟空','1111','北京','空军总医院','外科','就是厉害','{$date}')";
        $db->exec($sql);
        $sql = "insert into doctor values ('b','唐僧','1111','北京','空军总医院','外科','就是厉害','{$date}')";
        $db->exec($sql);
        $sql = "insert into doctor values ('c','沙和尚','1111','北京','空军总医院','外科','就是厉害','{$date}')";
        $db->exec($sql);
        $db->close();
    }
    return;
}